package com.bangbang.blog.controller;


import com.alibaba.fastjson.JSONObject;
import com.bangbang.blog.pojo.FileDTO;
import com.bangbang.blog.pojo.SectionDTO;
import com.bangbang.blog.pojo.TbCourse;
import com.bangbang.blog.pojo.TbTeacher;
import com.bangbang.blog.service.ITbCourseService;
import com.bangbang.config.IdWorker;
import com.bangbang.configresult.Result;
import com.bangbang.configresult.ResultEnum;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 课程商品表 前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2021-08-11
 */
@RestController
@RequestMapping("course")
@RefreshScope
// 动态获取并刷新配置
public class TbCourseController {

    @Autowired
    private ITbCourseService iTbCourseService;
    @Autowired
    private RedisTemplate redisTemplate;
    //  查
    @ApiOperation(value = "课程管理查询方法")
    /*@ApiImplicitParams({
            @ApiImplicitParam(name = "couName",value = "课程名称",required = true,paramType = "query"),
            @ApiImplicitParam(name = "couTeacherId",value = "教师ID",required = true,paramType = "query"),
            @ApiImplicitParam(name = "couHour",value = "课时",required = true,paramType = "query"),
            @ApiImplicitParam(name = "couWhetherLiveStreaming",value = "是否直播课",required = true,paramType = "query"),

    })*/
//    @RequestParam("couName")String couName, @RequestParam("couTeacherId")String couTeacherId,@RequestParam("couHour")int couHour,@RequestParam("couWhetherLiveStreaming")int cou_whether_live_streaming
    @GetMapping
    public Result queryCourse(){
//            List<TbCourse> tbCourse = iTbCourseService.selectByMap(couName,couTeacherId,couHour,couWhetherLiveStreaming);
            List<TbCourse> tbCourseList = iTbCourseService.query().list();
//            if(tbCourse == null){
//                return Result.buildResult(ResultEnum.SUCCESS).setResult("暂无此课程");
//            }
        return Result.buildResult(ResultEnum.SUCCESS).setResult(tbCourseList);
    }

    //  新增
    @ApiOperation(value = "课程管理新增方法")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "course",value = "课程详情",required = true,paramType = "body"),
    })
    @PostMapping
    public Result queryCourse(@RequestBody TbCourse course){
        //Object o1 = redisTemplate.boundValueOps("").get();
        Object o1 = redisTemplate.boundValueOps("f8d51ba6-fd96-4e59-9d9e-0a873eed2b9e").get();
        //TbTeacher o = (TbTeacher)JSONObject.toJSON(teacher);
       //List<TbTeacher> list = JSONObject.parseArray(teacher, TbTeacher.class);
       // TbTeacher o = (TbTeacher)JSONObject.parse(teacher);
        String s = o1.toString();


        //List<TbTeacher> list = JSONObject.parseArray(JSONObject.toJSONString(teacher), TbTeacher.class);
        //Object o1 = redisTemplate.boundValueOps("d9cf212b-8c0a-4b5f-99e3-6af12a75f4ab").get();
        //List<TbTeacher> list = JSONObject.parseArray(JSONObject.toJSONString(o1), TbTeacher.class);


        course.setCouTeacherId(s);
        IdWorker idWorker = new IdWorker();
        course.setCouId(idWorker.nextId());
        iTbCourseService.save(course);
        return Result.buildResult(ResultEnum.SUCCESS).setResult("新增成功");
    }

    @ApiOperation("课程软删除")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "deleteById", value = "删除课程", required = true, paramType = "path")
    })
    @DeleteMapping("/{courseId}")
    public Result deleteById(@PathVariable("courseId")Integer courseId){
        iTbCourseService.deleteById(courseId);
        return Result.buildResult(ResultEnum.SUCCESS).setResult("删除课程成功");
    }


}

